package com.ych.controller;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ych.beans.Alarm;
import com.ych.beans.Message;
import com.ych.service.AlarmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/alarm/alarm")
public class AlarmController {
    @Autowired
    AlarmService service;

    @PostMapping
    public Message addAlarm(@RequestBody Alarm alarm){
        return service.addAlarm(alarm);
    }

    @GetMapping
    public Message selectAlarm(@RequestParam Integer pageNo,
                               @RequestParam(required = false) Boolean key,
                               @RequestParam(required = false) @JsonFormat(pattern = "yy-MM-dd HH:mm:ss") Date from,
                               @RequestParam(required = false) @JsonFormat(pattern = "yy-MM-dd HH:mm:ss") Date end){
        return service.selectAlarm(pageNo,key,from,end);
    }

    @PutMapping
    public Message updateAlarm(@RequestBody Alarm alarm){
        return service.updateAlarm(alarm);
    }
}
